ideb_plot <-
  brazil_data %>% 
  filter(urb == 1) %>%
  #filter(ideb_score != 0) %>%
  select(pop_2010, ideb_2005) %>%
  ggplot(aes(x=pop_2010, y = ideb_2005)) +
  geom_smooth(method = "loess", color = "black") +
  stat_summary_bin(fun='mean', bins=20,
                   shape = 21, fill = "lightgrey",
                   color='black', size=1.5, geom='point') +
  theme_bw() +
  scale_colour_grey() +
  scale_x_continuous(trans = 'log10',
                     breaks = trans_breaks('log10', function(x) 10^x),
                     labels = trans_format('log10', math_format(10^.x))) +
  theme(panel.grid.minor = element_blank(), 
        panel.grid.major.x = element_blank(),
        axis.line.y.left = element_blank(),
        legend.position = "bottom",
        strip.background = element_blank(),
        legend.title = element_blank(),
        axis.line = element_line(colour = "black"),
        panel.border = element_blank(),
        axis.title.y = element_blank()) +
  xlab("Log (Population)") +
  ggtitle("IDEB Score (1-10, 2011)") +
  ylim(0, 10)
  
ggsave("./_4_outputs/figure_oa_vi.pdf", plot = ideb_plot, width = 5, height = 2.5)
